<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Services\OSS;
use App\Services\CommonService;
use Illuminate\Http\Request;
use App\Services\CourseTypeService;

class CommonController extends Controller{
	public function gettoken(){
		$common = new CommonService;
		$token = $common->getRandomToken();
		return response()->json(array('code'=>200,'_token'=>$token));
	}
	public function upload(Request $request){

		$id = $request->input('courseid');
		$file = $request->file('material_file');

		$file_path = $request->input('course');

		$common = new CommonService;
		$file_message = $common->uploads($file,$file_path,$id);
		// $file_message = array('code'=>200,'imgurl'=>'course_1/d010d0e09077608ee21fccc150d6fa39.jpg');

		return response()->json($file_message);
	}

	public function getprovincelist(){
		$common = new CommonService;
		$provincelist = $common->getProvinceList();

		$data = array('code'=>200,'provincelist'=>$provincelist);
		return response()->json($data);
	}

	public function getcitylist($id){
		$common = new CommonService;
		$citylist = $common->getCityList($id);
		if(!empty($citylist)){
			$data = array('code'=>200,'citylist'=>$citylist);
		}else{
			$data = array('code'=>400,'citylist'=>'');
		}

		return response()->json($data);
	}

	public function getcountylist($id){
		$common = new CommonService;
		$countylist = $common->getCityList($id);

		if(!empty($countylist)){
			$data = array('code'=>200,'countylist'=>$countylist);
		}else{
			$data = array('code'=>400);
		}

		return response()->json($data);
	}

	public function getColumnList($pid){
		$courseType = new CourseTypeService;
		$courseList = $courseType->getCourseTypeList(20,'',$pid);

		if(!empty($courseList)){
			$data = array('code'=>200,'list'=>$courseList);
		}else{
			$data = array('code'=>400);
		}

		return response()->json($data);
	}
}
